package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.mall.commons.exception.ExceptionProcessorUtils;
import com.cskaoyan.mall.constant.ShoppingRetCode;
import com.cskaoyan.shopping.converter.TestProductDetailConverter;
import com.cskaoyan.shopping.dal.entitys.Item;
import com.cskaoyan.shopping.dal.persistence.ItemMapper;
import com.cskaoyan.shopping.dto.TestProductDetailDto;
import com.cskaoyan.shopping.dto.TestProductDetailRequest;
import com.cskaoyan.shopping.dto.TestProductDetailResponse;
import com.cskaoyan.shopping.service.ITestProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @auther cskaoyan
 * @date 2022/5/18:11:42
 */
@Service
public class ITestProductServiceImpl implements ITestProductService {

    @Autowired
    ItemMapper itemMapper;

    @Autowired
    TestProductDetailConverter testProductDetailConverter;

    @Override
    public TestProductDetailResponse getProductDetail(TestProductDetailRequest request) {

        TestProductDetailResponse testProductDetailResponse = new TestProductDetailResponse();
        try {
            // 参数校验
            request.requestCheck();
            // 查询商品数据
            Item item = itemMapper.selectByPrimaryKey(request.getProductId());
            TestProductDetailDto result = testProductDetailConverter.testProductDoToProductDto(item);

            // 成功执行
            // 放入数据
            testProductDetailResponse.setTestProductDetailDto(result);
            testProductDetailResponse.setCode(ShoppingRetCode.SUCCESS.getCode());
            testProductDetailResponse.setMsg(ShoppingRetCode.SUCCESS.getMessage());
        } catch (Exception e) {
            e.printStackTrace();
            ExceptionProcessorUtils.wrapperHandlerException(testProductDetailResponse, e);
        }

        return testProductDetailResponse;
    }
}
